package com.liesheng.haylou.common;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.liesheng.haylou.R;
import com.liesheng.haylou.utils.DeviceUtil;
import com.liesheng.haylou.utils.glide.transformation.BlurTransformation;
import com.liesheng.haylou.utils.glide.transformation.GrayscaleTransformation;
import com.liesheng.haylou.utils.glide.transformation.RoundedCornersTransformation;

/**
 * Date:2019/11/7
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description: glide处理图片的工具类
 */
public class GlideHelper {

    private static int placeDrawable = R.drawable.ic_launcher_foreground;//占位图

    private static int errorDrawable = R.drawable.ic_launcher_foreground;//错误图

    public static void loadImage(ImageView view,String url){
        Glide.with(view.getContext())
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(placeDrawable)
                .error(errorDrawable)
                .into(view);
    }

    public static void loadRoundImage(ImageView view,String url){
        int radius = DeviceUtil.dip2px(5);
        Glide.with(view.getContext())
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(placeDrawable)
                .error(errorDrawable)
                .transform(new RoundedCornersTransformation(view.getContext(), radius, 0))
                .into(view);
    }
    public static void loadCicleImage(ImageView view,String url){
        int radius = DeviceUtil.dip2px(5);
        Glide.with(view.getContext())
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(placeDrawable)
                .error(errorDrawable)
                .transform(new RoundedCornersTransformation(view.getContext(), radius, 0))
                .into(view);
    }

    //黑白的圆角图片
    public static void loaGrayImage(ImageView view,String url){
        int radius = DeviceUtil.dip2px(5);
        Glide.with(view.getContext())
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(placeDrawable)
                .error(errorDrawable)
                .transform(new GrayscaleTransformation(view.getContext()), new RoundedCornersTransformation(view.getContext(), radius, 0))
                .into(view);
    }

    //毛玻璃效果
    public static void loaBlurImage(ImageView view,String url){
        int radius = DeviceUtil.dip2px(5);
        Glide.with(view.getContext())
                .load(url)
                .placeholder(placeDrawable)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new BlurTransformation(view.getContext(), radius))
                .into(view);
    }

}
